import * as path from "path";
import * as fs from "fs";
import * as Router from "koa-router";
const routes = new Router({ prefix: "/api" })
//自动注册路由
const filePath = path.resolve(__dirname, "./")
const routeAuto = (filePath: string) => {
    fs.readdirSync(filePath).forEach(file => {
        if (file.includes(".ts") || file.includes(".js")) {
            if (file !== "index.ts" && file !== "index.js") {
                let { route } = require(filePath + "/" + file)
                routes.use(route.routes())
                routes.use(route.allowedMethods())
            }
        } else {
            routeAuto(path.resolve(filePath, file))
        }
    })

}

routeAuto(filePath)


export {
    routes
}

